function quickSort(arr) {
  let l = arr.length;
  if (l === 0) {
    return arr
  }
  // 获取中位数
  let pivotIdx = parseInt(l / 2)
  let pivotVal = arr.splice(pivotIdx, 1)[0]

  let leftArr = []
  let rightArr = []
  let i = 0

  while (i < l - 1) {
    if (arr[i] > pivotVal) {
      rightArr.push(arr[i])
    } else if (arr[i] <= pivotVal) {
      leftArr.push(arr[i])
    }
    i++
  }

  return quickSort(leftArr).concat([pivotVal], quickSort(rightArr))

}

let arr = [-10, 10, 1, 34, 5, 1]
quickSort(arr)// [-10, 1, 1, 5, 10, 34]